package com.atguigu.graph;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;

public class Graph {

    //图节点的集合
    ArrayList<String> arrayList;
    //二维数组，代表图各节点之间的关系
    int arr[][];


    public Graph(int n){
        this.arrayList = new ArrayList<String>(n);
        this.arr = new int[n][n];
    }

    public static void main(String[] args) {
        Graph graph = new Graph(5);
        String strArr[] = {"A","B","C","D","E"};

        for (String s : strArr) {
            graph.addNode(s);
        }


        graph.createArray(0,1,1);
        graph.createArray(0,2,1);
        graph.createArray(1,2,1);
        graph.createArray(1,3,1);
        graph.createArray(1,4,1);

        graph.order();
    }

    public void addNode(String str){
        arrayList.add(str);
    }

    //创建二维数组
    public void createArray(int val1,int val2,int gx){
        arr[val1][val2] = gx;
    }

    //二维数组遍历
    public void order(){
        for (int[] ints : arr) {
            System.out.println(Arrays.toString(ints));
        }
    }

}
